﻿using System;
using System.Linq;

using Ewk.Math.ComputationTypes;
using Ewk.UnitTests;

namespace Ewk.Math.Algebra.UnitTests
{
    public abstract class AlgebraUnitTestsBase<T> : UnitTestBase
        where T : struct, IComparable, IFormattable, IConvertible, IComparable<T>, IEquatable<T>
    {
        protected static Computable<T>[] CreateComputables(params T[] values)
        {
            return values.Select(CreateComputable).ToArray();
        }

        protected static Computable<T> CreateComputable(T value)
        {
            return Computable<T>.Factory.Create(value);
        }

        protected static Matrix<T> CreateMatrix(int rowCount, int columnCount, Func<int, int, Computable<T>> action)
        {
            var elements = new Computable<T>[rowCount, columnCount];

            for (var i = 0; i < rowCount; i++)
            {
                for (var j = 0; j < columnCount; j++)
                {
                    elements[i, j] = action(i, j);
                }
            }

            return new Matrix<T>(elements);
        }

        protected static Matrix<T> CreateMatrix(T[,] values)
        {
            return new Matrix<T>(values);
        }

        protected static Vector<T> CreateVector(params Computable<T>[] elements)
        {
            return new Vector<T>(elements);
        }

        protected static Vector<T> CreateVector(params T[] values)
        {
            return new Vector<T>(values);
        }
    }
}
